import request from '@/router/axios';
export const saveCust = (custInfoDto) => { // 新增客户
  return request({
    url: '/api/blade-custom/custInfo/saveCust',
    method: 'post',
    headers: {
      'Content-Type': "application/json"
    },
    data:custInfoDto
  })
}

export const editCust = (custInfoDto) => { // 编辑客户
  return request({
    url: '/api/blade-custom/custInfo/editCust',
    method: 'post',
    headers: {
      'Content-Type': "application/json"
    },
    data:custInfoDto
  })
}

export const queryCustType = (userid) => { // 查询客户分组
  return request({
    url: '/api/blade-custom/custType/queryCustType',
    method: 'post',
    data:{
      userid
    }
  })
}

export const queryCustType1 = (userid) => { // 查询客户分组(迭代版)
  return request({
    url: '/api/blade-custom/custType/queryCustType1',
    method: 'post',
    data:{
      userid
    }
  })
}


export const saveCustType = (className,pid=0) => { // 保存客户分类
  return request({
    url: '/api/blade-custom/custType/saveCustType',
    method: 'post',
    data: {
      className,
      pid,
      fixed:0
    }
  })
}

export const editCustType = (className, id, pid, isShow) => { // 修改客户分类
  return request({
    url: '/api/blade-custom/custType/editCustType',
    method: 'post',
    data: {
      className,
      id,
      pid,
      isShow
    }
  })
}

export const showCustType = (id, isShow) => { // 修改客户分类
  return request({
    url: '/api/blade-custom/custType/showOrHiden',
    method: 'post',
    data: {
      id,
      isShow
    }
  })
}


export const deleteCustType = (id) => { // 删除客户分类
  return request({
    url: '/api/blade-custom/custType/deleteCustType',
    method: 'post',
    data: {
      id
    }
  })
}

export const deleteCust = (id) => { // 删除客户
  return request({
    url: '/api/blade-custom/custInfo/deleteCust',
    method: 'post',
    params: {
      id
    }
  })
}


export const deleteBatchCust = (ids) => { // 批量删除
  return request({
    url: '/api/blade-custom/custInfo/deleteBatchCust',
    method: 'post',
    params: {
      ids: ids.toString()
    }
  })
}


export const updateCust = (custInfoDto) => { // 修改客户
  return request({
    url: '/api/blade-custom/custInfo/saveCust',
    method: 'post',
    data: {
      custInfoDto
    }
  })
}

export const custList = (ispublic,typeId,userid,manager,size, current, sortField, sortType) => { // table list
  let sort = []
  if (sortField) {
    sort = [{
      sortField,
      sortType
    }]
  }
  return request({
    url: '/api/blade-custom/custInfo/queryCust',
    method: 'post',
    data: {
      ispublic,
      typeId,
      userid,
      manager,
      size,
      current,
      sortDtos: sort
    }
  })
}

export const queryCust = (id) => { // 查询单个id
  return request({
      url: `/api/blade-custom/custInfo/detail/${id}`,
      method: 'get'
      })
}

export const lightCustInfo = (id, light) => { // 点亮客户置顶
  return request({
    url: '/api/blade-custom/custInfo/lightCustInfo',
    method: 'post',
    data: {
      id,
      light
    }
  })
}

export const deleteCustMark = (id) => { // 删除客户标签
  return request({
    url: '/api/blade-custom/custMark/deleteCustMark',
    method: 'post',
    params: {
      id
    }
  })
}

export const editCustMark = (id,markColor,markName) => { // 修改客户标签
  return request({
    url: '/api/blade-custom/custMark/editCustMark',
    method: 'post',
    data:{
      id,
      markColor,
      markName
    }
  })
}

export const queryCustMark = (userid) => { // 查询客户标签
  return request({
    url: '/api/blade-custom/custMark/queryCustMark',
    method: 'post',
    data: {
      userid
    }
  })
}

export const saveCustMark = (markColor, markName, userid) => { // 增加客户标签
  return request({
    url: '/api/blade-custom/custMark/saveCustMark',
    method: 'post',
    data:{
      markColor,
      markName,
      userid
    }
  })
}

export const saveSource = (name) => { // 保存客户来源
  return request({
    url: '/api/blade-custom/custResource/saveCustResource',
    method: 'post',
    data:{
      name
    }
  })
}

export const editSource = (id,name) => { // 修改客户来源
  return request({
    url: '/api/blade-custom/custResource/editCustResource',
    method: 'post',
    data:{
      id,
      name
    }
  })
}

export const deleteSource = (id) => { // 删除客户来源
  return request({
    url: '/api/blade-custom/custResource/deleteCustResource',
    method: 'post',
    params: {
      id
    }
  })
}



export const queryCustResource = () => { // 查询客户来源
  return request({
    url: '/api/blade-public/dictCommon/queryDict2',
    method: 'post',
    data:{
      dictKey: "客户来源"
    }
  })
}

export const queryCustContent = () => { // 客户左侧菜单
  return request({
    url: '/api/blade-custom/custInfo/leftContent',
    method: 'get',
  })
}

export const markCust = (custIds,markIds) => { // 客户标记客户
  return request({
    url: '/api/blade-custom/custInfo/markCust',
    method: 'post',
    data:{
      custIds,
      markIds
    }
  })
}

export const moveGroup = (custIds,typeId) => { // 移动客户到某一分组
  return request({
    url: '/api/blade-custom/custInfo/moveGroup',
    method: 'post',
    data:{
      custIds,
      typeId
    }
  })
}

export const mergeCust = (custIds) => { // 合并客户
  return request({
    url: '/api/blade-custom/custInfo/mergeCust',
    method: 'post',
    params:{
      custIds
    }
  })
}

export const flowUp = (followContent, custid,followType, linker) => { // 跟进客户
  return request({
    url: '/api/blade-custom/custFollow/flowUp',
    method: 'post',
    data:{
      followContent,
      custid,
      followType,
      linker
    }
  })
}

export const getFlowUp = (custId,current, size, operContent, timeSort, operType = 0, linker) => { // 客户跟进记录
  return request({
    url: `/api/blade-custom/custFollow/getFlowUp`,
    method: 'post',
    data: {
      custid:custId,
      current,
      size,
      operContent,
      timeSort,
      operType,
      linker
    }
  })
}

export const getOperation= (custId, current, size) => { // 客户操作记录
  return request({
    url: `/api/blade-custom/tCustPublicLog/list/${custId}`,
    method: 'post',
    data: {
      current,
      size
    }
  })
}


export const shareCust = (custIds, userIds) => { // 共享客户
  return request({
    url: '/api/blade-custom/custInfo/shareCust',
    method: 'post',
    data:{
      custIds, // 客户id
      userIds // 用户id
    }
  })
}

export const enterpriseUser = () => { // 共享客户列表 (查询企业所有用户)
  return request({
    url: '/api/blade-public/bladeUser/findUserByCrop',
    method: 'post'
  })
}

export const findUserSubTree = () => { // 自己和下属客户
  return request({
    url: '/api/blade-public/bladeUser/findUserSubTree',
    method: 'post'
  })
}

export const transferCust = (custIds, transferUserIds) => { // 转移客户
  return request({
    url: '/api/blade-custom/custInfo/transferCust',
    method: 'post',
    data: {
      custIds,
      transferUserIds
    }
  })
}

export const querySubordinates = () => { // 下属及当前客户集合
  return request({
    url: '/api/blade-public/bladeUser/branch1',
    method: 'post'
  })
}

export const getCustField = (userid) => { // 客户列表显示字段
  return request({
    url: '/api/blade-custom/custInfo/getCustField',
    method: 'post',
    data: {
      userid
    }
  })
}

export const getCustField1 = () => { // 客户列表显示字段(公海)
  return request({
    url: '/api/blade-custom/custInfo/getCustField1',
    method: 'post'
  })
}

export const setCustField1 = (fieldDtos) => { // 更改客户列表显示字段（公海）
  return request({
    url: '/api/blade-custom/custInfo/setCustField1',
    method: 'post',
    data: {
      fieldDtos
    }
  })
}

export const setCustField = (fieldDtos) => { // 更改客户列表显示字段
  return request({
    url: '/api/blade-custom/custInfo/setCustField',
    method: 'post',
    data: {
      fieldDtos
    }
  })
}

export const cancelFlowUp = (custIds) => { // 取消跟进
  return request({
    url: `/api/blade-custom/custFollow/cancelFlowUp/${custIds}`,
    method: 'get',
    params: {
      custIds
    }
  })
}

export const queryAdvanced = (userid, ispublic, typeId,manager, params, markIds, typeIds, current, size, sortField, sortType) => { // 高级查询兼分页
  let sort = []
  if (sortField != '') {
    sort = [{
      sortField,
      sortType
    }]
  }
  return request({
    url: '/api/blade-custom/custInfo/queryAdvanced',
    method: 'post',
    data: {
      userid,
      params,
      markIds,
      typeIds,
      manager,
      current,
      size,
      ispublic,
      typeId,
      sortDtos: sort
    }
  })
}

export const queryMyCust = (typeId, params, markIds, typeIds, current, size, sortField, sortType) => { // 我的客户（分组）
  let sort = {}
  if (sortField != '') {
    sort = {
      sortField,
      sortType
    }
  }

  return request({
    url: `/api/blade-custom/custInfo/queryMyCust`,
    method: 'post',
    data: {
      typeId,
      typeIds,
      params,
      markIds,
      current,
      size,
      sortDto: sort
    }
  })
}

export const querySubCust = (userid,typeId, params, markIds, typeIds, current, size, sortField, sortType) => { // 下属客户
  let sort = {}
  if (sortField != '') {
    sort = {
      sortField,
      sortType
    }
  }

  return request({
    url: `/api/blade-custom/custInfo/querySubCust`,
    method: 'post',
    data: {
      userid,
      typeId,
      typeIds,
      params,
      markIds,
      current,
      size,
      sortDto: sort
    }
  })
}


export const querySeaCust = (typeId, params, markIds, typeIds, current, size, sortField, sortType) => { // 公海客户
  let sort = {}
  if (sortField != '') {
    sort = {
      sortField,
      sortType
    }
  }

  return request({
    url: `/api/blade-custom/custInfo/querySeaCust`,
    method: 'post',
    data: {
      typeId,
      typeIds,
      params,
      markIds,
      current,
      size,
      sortDto: sort
    }
  })
}

export const queryShareCust = (typeId, params, markIds, typeIds, current, size, sortField, sortType) => { // 共享客户
  let sort = {}
  if (sortField != '') {
    sort = {
      sortField,
      sortType
    }
  }

  return request({
    url: `/api/blade-custom/custInfo/queryShareCust`,
    method: 'post',
    data: {
      typeId,
      typeIds,
      params,
      markIds,
      current,
      size,
      sortDto: sort
    }
  })
}


export const movePrivateSea = (typeId, custIds) => { // 移入私海
  return request({
    url: `/api/blade-custom/custInfo/movePrivateSea`,
    method: 'post',
    data: {
      typeId,
      custIds
    }
  })
}

export const seaAllot = (userid, custIds) => { // 分配客户
  return request({
    url: `/api/blade-custom/custInfo/seaAllot`,
    method: 'post',
    data: {
      userid,
      custIds
    }
  })
}

export const deptTree = () => { // 公司部门
  return request({
    url: `/api/blade-public/sysdept/deptTree`,
    method: 'get'
  })
}

export const findUserByCrops = (deptId) => { // 根据部门id,查询出该部门下的所有员工
  return request({
    url: `/api/blade-public/bladeUser/findUserByDept`,
    method: 'post',
    data: {
      deptId
    }
  })
}





export const findTree = () => { // 公司所有用户tree
  return request({
    url: `/api/blade-public/bladeUser/findUserTree`,
    method: 'post',
  })
}

export const findUserByCrop = () => { // 公司所有用户评级
  return request({
    url: `/api/blade-public/bladeUser/findUserByCrop`,
    method: 'post',
  })
}


export const delMarkCust = (custIds, markId) => { // 删除客户标记
  let custMarkDtos = []
  custMarkDtos = [{markId}]
  return request({
    url: `/api/blade-custom/custInfo/delMarkCust`,
    method: 'post',
    data: {
      custIds,
      custMarkDtos
    }
  })
}


export const fullNameStore = () => {
  return request({
    url: `/api/blade-custom/custInfo/fullNameStore`,
    method: 'get',
  })
}

export const changeRate = (id,gradeType) => { // 修改客户评级
  return request({
    url: `/api/blade-custom/custInfo/gradeCust`,
    method: 'post',
    data: {
      id,
      gradeType
    }
  })
}

export const custOrder = (custId, current, size) => { // 客户相关订单
  return request({
    url: '/api/blade-order/orderInfo/custOrder',
    method: 'post',
    data: {
      custId,
      current,
      size
    }
  })
}

export const getShareUser = (id) => { // 已共享的客户集合
  return request({
    url: `/api/blade-custom/custInfo/getShareUser/${id}`,
    method: 'get'
  })
}

export const exportCust = () => { // 客户导出列表
  return request({
    url: `/api/blade-custom/custInfo/template`,
    method: 'get',
    responseType: 'blob'
  })
}

export const importCust = (custInfoDto) => { // 导入客户
  return request({
    url: `/api/blade-custom/custInfo/import`,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data:custInfoDto
  })
}

export const custImpList = (current, size) => { // 导入客户列表
  return request({
    url: '/api/blade-custom/custImp/list',
    method: 'get',
    params:{
      current,
      size
    }
  })
}

export const custImpDetail = (id,current, size) => { // 导入客户详情
  return request({
    url: `/api/blade-custom/custImpDetail/query/${id}`,
    method: 'get',
    params:{
      current,
      size
    }
  })
}

export const orderCount = (id,year) => { // 订单统计
  return request({
    url: `/api/blade-custom/custInfo/orderCount/${id}/${year}`,
    method: 'get'
  })
}

export const mailCount = (id,year) => { // 邮件统计
  return request({
    url: `/api/blade-custom/custInfo/custSendEmailCount/${id}/${year}`,
    method: 'get'
  })
}

export const canCelCust = (custIds) => { // 取消共享
  return request({
    url: `/api/blade-custom/custInfo/canCelCust  `,
    method: 'post',
    data:{
      custIds
    }
  })
}

export const isAdmin = () => { // 是否为管理员
  return request({
    url: `/api/blade-custom/custType/isAdmin`,
    method: 'get'
  })
}

export const getSourceList = () => { // 客户来源列表
  return request({
    url: `/api/blade-custom/custResource/query`,
    method: 'get'
  })
}

export const saveSourceAdmin = (name) => { // 保存来源
  return request({
    url: `/api/blade-custom/custResource/save`,
    method: 'post',
    data: {
      name
    }
  })
}

export const editSourceAdmin = (id, name) => { // 修改来源
  return request({
    url: `/api/blade-custom/custResource/edit`,
    method: 'post',
    data: {
      id,
      name
    }
  })
}

export const deleteSourceAdmin = (id) => { // 删除来源
  return request({
    url: `/api/blade-custom/custResource/delete/${id}`,
    method: 'get'
  })
}
